#include "fig_boss_attackmove_godown.h"
#include "fig_boss_attackmove_manager.h"
#include "fig_enemy_boss.h"

FIGBossAttackMoveGoDown::FIGBossAttackMoveGoDown(FIGBossAttackMoveManager* pManager) :
															FIGBossAttackMove(pManager),
															m_State(STATE_TRANSFORM_BACK)
{

}




void		FIGBossAttackMoveGoDown::Tick(float dt)
{
	FIGEnemyBoss* pBoss = m_pManager->GetBoss();	
	if(!pBoss)
		return;

	FIGBossAttackMove::Tick(dt);

	if(m_Delay > 0)
		return;

	pBoss->m_bShouldTakeLessDamage = true;

	switch(m_State)
	{
		case STATE_TRANSFORM_TO_NORMAL:
		{
			bool IsFinish = pBoss->m_Bone.TransformForwardTick(dt * 2.0f);
			if(IsFinish)
				NextState();
		}

			break;
		case STATE_TRANSFORM_BACK:
		{
			bool IsFinish = pBoss->m_Bone.TransformBackwardTick(dt * 2.0f);
			if(IsFinish)
				NextState();
		}
		break;

		case STATE_GOINGDOWN:
		{
			const math::Vec2 Dir = math::Vec2(0,1.0f);
			float Dist = dt * m_Acceleration;
			pBoss->m_Pos += ( Dir * Dist);
			m_Acceleration += dt;

			if(!pBoss->IsInSideScreen())
			{
				NextState();		
				pBoss->m_Pos = math::Vec2(0.5f, - pBoss->GetRadius());
				m_Acceleration = 1.0f;
			}
		}
		break;

		case STATE_COMINGIN_TOP:
		{

			const math::Vec2 Dir = math::Vec2(0,1.0f);
			float Dist = dt * m_Acceleration;
			pBoss->m_Pos += ( Dir * Dist);
			if(m_Acceleration > 0.1f)
				m_Acceleration -= dt;

			if(pBoss->m_Pos.y > pBoss->m_ComeInStopY)
				NextState();
			
		}
			break;
		
		case STATE_TRANSFORM:
			{			
			pBoss->m_ShootCounter.ForceReady();		// shoot as soon as possible
			pBoss->m_bShouldTakeLessDamage = false;
			bool IsFinish = pBoss->m_Bone.TransformForwardTick(dt * 2.0f);
			if(IsFinish)
				m_pManager->End();
			}
			break;

		default:
			break;

	}
	
}


void		FIGBossAttackMoveGoDown::Start(float Delay)
{
	FIGBossAttackMove::Start(Delay);
	m_State = STATE_TRANSFORM_TO_NORMAL;
	m_Acceleration = 1.0f;	
	FIGEnemyBoss* pBoss = m_pManager->GetBoss();
	if(pBoss && pBoss->IsAlive())
		pBoss->m_Bone.CopyToBackup();
}


void		FIGBossAttackMoveGoDown::NextState()
{
	int Temp = (int)m_State;
	Temp++;
	m_State = (FIGBossAttackMoveGoDown::ATTACKGODOWN_STATE)Temp;
}

